package core.collection.mycollection;

import core.collection.bean.Student;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 集合的遍历之迭代器遍历
 *
 *      迭代器概述
 *          集合是用来存储元素，存储的元素需要查看，那么就需要迭代（遍历）
 *      案例演示
 *          迭代器的使用
 *
 * @author
 * @create 2018-12-23 8:22
 **/
public class mycollection_5_Collection_Iterator {
    public static void main(String[] args){
        Collection list = new ArrayList();
        list.add(new Student("tom",23));
        list.add(new Student("jack",23));
        list.add(new Student("juice",23));
        Iterator it = list.iterator();
        //获取迭代器
        while (it.hasNext()){
            Student s = (Student)it.next();
            System.out.println(s.getName()+"..."+s.getAge());
        }
    }
}
